package com.leostadyn.stackfarm.timestatistics.view.activity.setting;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.leostadyn.stackfarm.timestatistics.R;
import com.leostadyn.stackfarm.timestatistics.base.BaseApplication;
import com.leostadyn.stackfarm.timestatistics.common.Constants;
import com.leostadyn.stackfarm.timestatistics.model.bean.UserBean;
import com.leostadyn.stackfarm.timestatistics.utils.SaveObjectTools;
import com.leostadyn.stackfarm.timestatistics.view.activity.LoginActivity;
import com.orhanobut.hawk.Hawk;

import me.drakeet.materialdialog.MaterialDialog;


public class SettingActivity extends AppCompatActivity {
    private LinearLayout layout_modify_password;
    private TextView nav_txt_title;
    private UserBean userBean;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);

        userBean = (UserBean) SaveObjectTools.INSTANCE().getObjectData(Constants.USERINFO);

        nav_txt_title = findViewById(R.id.nav_txt_title);
        nav_txt_title.setText("系统设置");

        findViewById(R.id.nav_img_back).setOnClickListener(v -> finish());

        layout_modify_password = findViewById(R.id.layout_modify_password);

        layout_modify_password.setOnClickListener(v -> startActivity(new Intent(this, SystemChangePdwActivity.class)));
    }

    public void onLogout() {
        Hawk.deleteAll();
        //SaveObjectTools.INSTANCE().saveData(null, Constants.USERINFO);
        Intent intent = new Intent(this, LoginActivity.class);
        Hawk.delete("account");
        Hawk.delete("password");
        Hawk.delete("token");
        //intent.setAction(BuildConfig.APPLICATION_ID);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        BaseApplication.getApplication().startActivity(intent);
    }

    public void onLoginOut(View view) {
        final MaterialDialog mMaterialDialog = new MaterialDialog(this);
        mMaterialDialog.setMessage("确定退出吗？")
                .setPositiveButton("确定", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mMaterialDialog.dismiss();
                        onLogout();
                    }
                }).setNegativeButton("取消", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mMaterialDialog.dismiss();
            }
        });
        mMaterialDialog.show();
    }

}
